package NotifyTest;

public class ThtradNotify implements Runnable{
    private int count = 0;

    @Override
    public void run() {

            synchronized (this){
                if (count<=200){
                    System.out.println(Thread.currentThread().getName()+":"+count++);
                    notify();//唤醒其他正在等待的线程
                }else {
                    try {
                        wait();//当前线程进入等待状态
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        }
    public static void main(String[] args) {
        ThtradNotify thtradNotify = new ThtradNotify();
        Thread thread1 = new Thread(thtradNotify);
        Thread thread2 = new Thread(thtradNotify);
        thread1.start();
        thread2.start();

    }
}
